package com.jinzhi.jzweb.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.common.utils.Result;
import com.jinzhi.jzweb.domain.MessagefailsDO;
import com.jinzhi.jzweb.service.MessagefailsService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * 
 * <pre>
 * 短信发送失败记录表
 * </pre>
 * <small> 2020-01-14 09:29:15 | lance</small>
 */
@Controller
@RequestMapping("/jzweb/messagefails")
public class MessagefailsController extends BaseController {
	@Autowired
	private MessagefailsService messagefailsService;
	
	@GetMapping()
	@RequiresPermissions("jzweb:messagefails:messagefails")
	String Messagefails(){
	    return "jzweb/messagefails/messagefails";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("jzweb:messagefails:messagefails")
	public Result<Page<MessagefailsDO>> list(MessagefailsDO messagefailsDTO){
        Wrapper<MessagefailsDO> wrapper = new EntityWrapper<MessagefailsDO>().orderBy("id", false);
        //wrapper.eq("name","jzweb");
        Page<MessagefailsDO> page = messagefailsService.selectPage(getPage(MessagefailsDO.class), wrapper);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("jzweb:messagefails:add")
	String add(){
	    return "jzweb/messagefails/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("jzweb:messagefails:edit")
	String edit(@PathVariable("id") Long id,Model model){
		MessagefailsDO messagefails = messagefailsService.selectById(id);
		model.addAttribute("messagefails", messagefails);
	    return "jzweb/messagefails/edit";
	}
	
	@Log("添加短信发送失败记录表")
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("jzweb:messagefails:add")
	public Result<String> save( MessagefailsDO messagefails){
		messagefailsService.insert(messagefails);
        return Result.ok();
	}
	
	@Log("修改短信发送失败记录表")
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("jzweb:messagefails:edit")
	public Result<String>  update( MessagefailsDO messagefails){
		boolean update = messagefailsService.updateById(messagefails);
		return update ? Result.ok() : Result.fail();
	}
	
	@Log("删除短信发送失败记录表")
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("jzweb:messagefails:remove")
	public Result<String>  remove( Long id){
		messagefailsService.deleteById(id);
        return Result.ok();
	}
	
	@Log("批量删除短信发送失败记录表")
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("jzweb:messagefails:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Long[] ids){
		messagefailsService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}
	
}
